%-----------------------------------------------------主文档 格式定义---------------------------------
\addtolength{\headsep}{-0.1cm}        %页眉位置
%\addtolength{\footskip}{0.4cm}       %页脚位置
%-----------------------------------------------------设定字体等------------------------------
\setmainfont{Times New Roman}    % 缺省字体
%\setCJKfamilyfont{song}{SimSun}
%\setCJKfamilyfont{hei}{SimHei}
%\setCJKfamilyfont{kai}{KaiTi}
%\setCJKfamilyfont{fs}{FangSong}
%\setCJKfamilyfont{li}{LiSu}
%\setCJKfamilyfont{you}{YouYuan}
%\setCJKfamilyfont{yahei}{Microsoft YaHei}
%\setCJKfamilyfont{xingkai}{STXingkai}
%\setCJKfamilyfont{xinwei}{STXinwei}
%\setCJKfamilyfont{fzyao}{FZYaoTi}
%\setCJKfamilyfont{fzshu}{FZShuTi}
%-------------------------------------------------------------------
\newCJKfontfamily\song{SimSun}
\newCJKfontfamily\hei{SimHei}
\newCJKfontfamily\kai{KaiTi}
\newCJKfontfamily\fs{FangSong}
\newCJKfontfamily\li{LiSu}
\newCJKfontfamily\you{YouYuan}
%\newCJKfontfamily\yahei{Microsoft YaHei}
\newCJKfontfamily\xingkai{STXingkai}
\newCJKfontfamily\xinwei{STXinwei}
\newCJKfontfamily\fzyao{FZYaoTi}
\newCJKfontfamily\fzshu{FZShuTi}

\setCJKmainfont[AutoFakeBold=6,AutoFakeSlant=.4]{SimSun}     %設定中文為系統上的字型，而英文不去更動
				%加了這二行後，就可以隨意的打中文，接下來的跟一般的LeTeX都一樣
                %AutoFakeBold設定粗體字要多粗
                %AutoFakeSlant設定斜體字要多斜，範圍-0.999到0.999，負值為往左斜
                %註：檔案一定要存在UTF-8的編碼格式才行

%以下四行非必要，但蠻好用的。
\defaultCJKfontfeatures{AutoFakeBold=6,AutoFakeSlant=.4} %以後不用再設定粗斜
\CJKsetecglue{\hskip 0.15em plus 0.05em minus 0.05em}
% slanfont: 允许斜体
% boldfont: 允许粗体
% CJKnormalspaces: 仅忽略汉字之间的空白,但保留中英文之间的空白。
% CJKchecksingle: 避免单个汉字单独占一行。
% CJKaddspaces: [备选]忽略汉字之间的空白,并且自动在中英文转换时插入空白。

\XeTeXlinebreaklocale "zh"           % 针对中文进行断行
\XeTeXlinebreakskip = 0pt plus 1pt minus 0.1pt

                                     % 给予TeX断行一定自由度

%-----------------------------------------------------------定义颜色---------------
\definecolor{blueblack}{cmyk}{0,0,0,0.35}%浅黑
\definecolor{darkblue}{cmyk}{1,0,0,0}%纯蓝
\definecolor{lightblue}{cmyk}{0.15,0,0,0}%浅蓝
%--------------------------------------------------------设定标题颜色--------------
\CTEXsetup[format+={\color{darkblue}}]{chapter}
\CTEXsetup[format+={\color{darkblue}}]{section}
\CTEXsetup[format+={\color{darkblue}}]{subsection}
%-----------------------------------------------------------定义、定理环境-------------------------
\newcounter{myDefinition}[chapter]\def\themyDefinition{\thechapter.\arabic{myDefinition}}
\newcounter{myTheorem}[chapter]\def\themyTheorem{\thechapter.\arabic{myTheorem}}
\newcounter{myCorollary}[chapter]\def\themyCorollary{\thechapter.\arabic{myCorollary}}

\tcbmaketheorem{defi}{定义}{fonttitle=\bfseries\upshape, fontupper=\slshape, arc=0mm, colback=lightblue,colframe=darkblue}{myDefinition}{Definition}
\tcbmaketheorem{theo}{定理}{fonttitle=\bfseries\upshape, fontupper=\slshape, arc=0mm, colback=lightblue,colframe=darkblue}{myTheorem}{Theorem}
\tcbmaketheorem{coro}{推论}{fonttitle=\bfseries\upshape, fontupper=\slshape, arc=0mm, colback=lightblue,colframe=darkblue}{myCorollary}{Corollary}
%------------------------------------------------------------------------------
\newtheorem{proof}{\indent\hei \textcolor{darkblue}{证明}}
\newtheorem{Solution}{\indent\hei \textcolor{darkblue}{解}}
%------------------------------------------------定义页眉下单隔线----------------
\newcommand{\makeheadrule}{\makebox[0pt][l]{\color{darkblue}\rule[.7\baselineskip]{\headwidth}{0.3pt}}\vskip-.8\baselineskip}
%-----------------------------------------------定义页眉下双隔线----------------
\makeatletter
\renewcommand{\headrule}{{\if@fancyplain\let\headrulewidth\plainheadrulewidth\fi\makeheadrule}}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{第\thechapter 章\quad #1}{}}    %去掉章标题中的数字
\renewcommand{\sectionmark}[1]{\markright{\thesection\quad #1}{}}    %去掉节标题中的点
\fancyhf{} %清空页眉
\fancyhead[RO]{\kai{\footnotesize.~\color{darkblue}\thepage~.}}         % 奇数页码显示左边
\fancyhead[LE]{\kai{\footnotesize.~\color{darkblue}\thepage~.}}         % 偶数页码显示右边
\fancyhead[CO]{\song\footnotesize\color{darkblue}\rightmark} % 奇数页码中间显示节标题
\fancyhead[CE]{\song\footnotesize\color{darkblue}\leftmark}  % 偶数页码中间显示章标题
%---------------------------------------------------------------------------------------------------------------------


%\hyphenpenalty=5000
%\tolerance=1000

\tolerance=1
\emergencystretch=\maxdimen
\hyphenpenalty=10000
\hbadness=10000



%-----------------------------------------------定义序号表格格式-D----------------
\setlist[enumerate,1]
{
    label=\arabic*.,   %标号适用阿拉伯数字，格式为 1. 2. 3.
    font=\textup,      %字体为上标
    leftmargin=7mm,    %第一个字离左边标号的距离
    labelsep=1.5mm,    %与标题之间的距离
    topsep=0mm,        %顶端的距离
    itemsep=-0.8mm     %与标题的距离
}

\setlist[enumerate,2]
{
    label=(a) ,   %标号适用阿拉伯数字，格式为 1. 2. 3.
    font=\textup,      %字体为上标
    leftmargin=7mm,    %第一个字离左边标号的距离
    labelsep=1.5mm,    %与标题之间的距离
    topsep=0mm,        %顶端的距离
    itemsep=-0.8mm     %与标题的距离
}

\setlist[itemize,1]
{
    font=\textup,      %字体为上标
    leftmargin=7mm,    %第一个字离左边标号的距离
    labelsep=1.5mm,    %与标题之间的距离
    topsep=0mm,        %顶端的距离
    itemsep=-0.8mm     %与标题的距离
}

\setlist[itemize,2]
{
    label=-,           %序号为—
    font=\textup,      %字体为上标
    leftmargin=7mm,    %第一个字离左边标号的距离
    labelsep=1.5mm,    %与标题之间的距离
    topsep=0mm,        %顶端的距离
    itemsep=-0.8mm     %与标题的距离
}

\setlist[itemize,3]
{
    label=*,           %序号为—
    font=\textup,      %字体为上标
    leftmargin=7mm,    %第一个字离左边标号的距离
    labelsep=1.5mm,    %与标题之间的距离
    topsep=0mm,        %顶端的距离
    itemsep=-0.8mm     %与标题的距离
}


%---------------------------------------------------------------------------------------------------------------------



%---------------------------代码环境设置
%\lstset{
%    language=C++,
%    numbers=left,
%    numberstyle= \tiny,
%    keywordstyle= \color{ blue!70},
%    commentstyle= \color{red!50!green!50!blue!50},
%    frame=shadowbox, % 阴影效果
%    rulesepcolor= \color{ red!20!green!20!blue!20} ,
%%    rulesepcolor= \color{gray} ,
%    escapeinside=``, % 英文分号中可写入中文
%    xleftmargin=2em,xrightmargin=2em, aboveskip=1em,
%    framexleftmargin=2em
%%    title=\lstname
%}

%
%\newtcblisting{mycode}[2]{
%breakable,
%drop shadow,
%listing engine=minted,
%minted style=trac,
%  minted language=#1,
%  minted options={fontsize=\small,linenos,numbersep=3mm},
%  listing only,
%  left=6mm,enhanced,title={#2},
%  colframe=blue!50!black,colback=blue!10!white,colbacktitle=blue!5!yellow!10!white,
%  fonttitle=\bfseries,coltitle=black,
%  attach boxed title to top center=
%  {yshift=-0.25mm-\tcboxedtitleheight/2,yshifttext=2mm-\tcboxedtitleheight/2},
%  boxed title style={enhanced,boxrule=0.5mm,
%    frame code={ \path[tcb fill frame] ([xshift=-4mm]frame.west)
%      -- (frame.north west) -- (frame.north east) -- ([xshift=4mm]frame.east)
%      -- (frame.south east) -- (frame.south west) -- cycle; },
%    interior code={ \path[tcb fill interior] ([xshift=-2mm]interior.west)
%      -- (interior.north west) -- (interior.north east)
%      -- ([xshift=2mm]interior.east) -- (interior.south east) -- (interior.south west)
%      -- cycle;} },
%  overlay={\begin{tcbclipinterior}\fill[red!20!blue!20!white] (frame.south west)
%      rectangle ([xshift=5mm]frame.north west);\end{tcbclipinterior}}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%\usemintedstyle{algol} %%全局设置
%% 设置 perl 行内代码样式
%\usemintedstyle[perl]{algol}
%\newmintinline{perl}{showspaces} %% 行内代码样式, showspaces 代表将空格先显式的打印出来



\newfontfamily\courier{Courier New}
\lstset{linewidth=1.05\textwidth,
        numbers=left, %设置行号位置
        language=C++,
        basicstyle=\small\courier,
        numberstyle=\tiny\courier, %设置行号大小
        keywordstyle=\color{blue}\courier, %设置关键字颜色
        %identifierstyle=\bf，
        commentstyle=\it\color[cmyk]{1,0,1,0}\courier, %设置注释颜色
        stringstyle=\it\color[RGB]{128,0,0}\courier,
        %framexleftmargin=10mm,
        frame=single, %设置边框格式
        backgroundcolor=\color[RGB]{245,245,244},
        %escapeinside=``, %逃逸字符(1左面的键)，用于显示中文
        breaklines, %自动折行
        extendedchars=false, %解决代码跨页时，章节标题，页眉等汉字不显示的问题
        xleftmargin=1em,xrightmargin=1em, aboveskip=1em, %设置边距
        tabsize=4, %设置tab空格数
        showspaces=false %不显示空格
        basicstyle=\small\courier
       }

%
%\definecolor{mygreen}{rgb}{0,0.6,0}
%\definecolor{mygray}{rgb}{0.5,0.5,0.5}
%\definecolor{mymauve}{rgb}{0.58,0,0.82}
%\lstset{
% backgroundcolor=\color{lightgray},
% basicstyle = \footnotesize,
% breakatwhitespace = false,
% breaklines = true,
% captionpos = b,
% commentstyle = \color{mygreen}\bfseries,
% extendedchars = false,
% frame =shadowbox,
% framerule=0.5pt,
% keepspaces=true,
% keywordstyle=\color{blue}\bfseries, % keyword style
% language = C++,                     % the language of code
% otherkeywords={string},
% numbers=left,
% numbersep=5pt,
% numberstyle=\tiny\color{mygray},
% rulecolor=\color{black},
% showspaces=false,
% showstringspaces=false,
% showtabs=false,
% stepnumber=1,
% stringstyle=\color{mymauve},        % string literal style
% tabsize=2,
% title=\lstname
%}
%---------------------------代码环境设置